import React from 'react';
import { withRouter,Link } from 'react-router-dom';
import { Menu } from 'antd';
import MenuItem from 'antd/lib/menu/MenuItem';
import routes from '@/routes';
import './index.css';
class Nav extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  render() {
    const {location}=this.props
    let current=null
    if (location.pathname==="/") {
      current="Home"
    }else if(location.pathname.indexOf("article")>-1){
      current="Article"
    }else{
      const filter=(routes.filter(e => {
        return e.path===location.pathname
      }))[0]
      current=filter?filter.key:''
    }
    return (
      <div className='nav container'>
        <Menu
          selectedKeys={[current]}
          mode='horizontal'
        >
          {routes.map((e) =>
            !e.hidden ? (
              <MenuItem key={e.key} icon={e.icon}>
                <Link to={e.path}>{e.name}</Link>
              </MenuItem>
            ) : null
          )}
        </Menu>
      </div>
    );
  }
}
export default withRouter(Nav);
